<div class="row">
    <div class="col-md-12">
        <div class="page-header">
            <h4>Topic: <#if response.OK>${response.result.topic.name}</#if> 
            	<#if response.OK && response.result.own>
            		<button type="submit" class="btn btn-success" data-target="#updateTopicRouteModal" data-toggle="modal" >修改路由</button>
            	</#if>
            </h4> 
        </div>
	</div>
</div>
<div class="row">
	<br/>
	<div class="col-md-12">
        <table class="table table-striped table-hover" style="margin-top: 0px">
                <thead>
	                <tr>
	                	<td>序号</td>
	                    <td>Broker</td>
	                    <td>读队列</td>
	                    <td>写队列</td>
	                    <td>权限</td>
	                </tr>
                </thead>
                <tbody>
	                <#if response.notOK || !response.result.topicRouteList??>
					     <tr>
		                    <td colspan=5 align="center">
		                    	暂无数据
		                    </td>
		                <tr>
					<#else>
						<#list response.result.topicRouteList as topicRoute>
							<tr>
								<td>${topicRoute_index + 1}</td>
		                    	<td>${topicRoute.brokerName}</td>
		                    	<td>${topicRoute.readQueueNums}</td>
		                    	<td>${topicRoute.writeQueueNums}</td>
		                    	<td><#if topicRoute.readable>可读</#if>,<#if topicRoute.writeable>可写</#if></td>
		                   	</tr>
						</#list>
					</#if>
                </tbody>
           </table>
    </div>
</div>

<div id="updateTopicRouteModal" class="modal fade" tabindex="-1" data-width="400">
	<div class="modal-dialog">
		<div class="modal-content">

			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				<h4 class="modal-title">Topic路由修改</h4>
			</div>

			<form class="form-horizontal form-bordered form-row-stripped" id="updateTopicRouteForm">
				<div class="modal-body">
					<div class="row">
						<!-- 控件开始 -->
						<div class="col-md-12">
							<!-- form-body开始 -->
							<div class="form-body">
								<div class="form-group">
									<label class="control-label col-md-3"> 队列数: </label>
									<div class="col-md-5">
										<input type="text" name="queueNum" value="${response.result.queueNum}" placeholder="队列数" class="form-control" />
									</div>
								</div>
								<div class="form-group">
									<label class="control-label col-md-3"> 申请原因: </label>
									<div class="col-md-5">
										<textarea type="text" name="info" rows="3" class="form-control" placeholder="请填写"></textarea>
									</div>
								</div>
								<input type="hidden" name="tid" value="${response.result.topic.id!}"/>
							</div>
							<!-- form-body 结束 -->
						</div>
						<div id="info"></div>
						<!-- 控件结束 -->
					</div>
				</div>
				
				<div class="modal-footer">
					<button type="button" data-dismiss="modal" class="btn" >取消</button>
					<button type="submit" id="updateTopicBtn" class="btn btn-primary">确定</button>
				</div>
			
			</form>
		</div>
	</div>
</div>
<script>
	$(function () {
        $('#updateTopicRouteForm').bootstrapValidator({
　　　　　　	message: 'This value is not valid',
            　		feedbackIcons: {
                　　　　　　　　valid: 'glyphicon glyphicon-ok',
                　　　　　　　　invalid: 'glyphicon glyphicon-remove',
                　　　　　　　　validating: 'glyphicon glyphicon-refresh'
            　　　　　　　　   },
            fields: {
            	queueNum: {
                    validators: {
                        between: {
			               message: '队列最小为1,最大为20',
			               min: '1',
			               max: '20'
                        }
                    }
                }
            }
        });
    }).on('success.form.bv', function(e) {
        // 阻止默认事件提交
        e.preventDefault();
        disable("updateTopicBtn");
		$.post('${request.contextPath}/topic/updateRoute',
				$("#updateTopicRouteForm").serialize(),
		        function(data){
		            if(data.status == 200){
						toastr.success("申请成功！请耐心等待！");  
						modalHide(3000, function(){
							$("#updateTopicRouteForm").data('bootstrapValidator').resetForm();
						});
				    }else{
				    	toastr.error("申请失败！"+data.message);  
				    	enable("updateTopicBtn");
				    }
		        }, 'json');
    });
</script>
